package com.hzlj.position.locate.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fz.common.base.dto.PageParamDTO;
import com.fz.common.base.dto.QueryPageResultDTO;
import com.fz.common.dict.annotation.DictConvert;
import com.hzlj.position.locate.common.dto.reportVideoJzry.ReportVideoJzryQueryParamDTO;
import com.hzlj.position.locate.common.dto.reportVideoJzry.ReportVideoJzryUpsertDTO;
import com.hzlj.position.locate.common.dto.reportVideoJzry.ReportVideoJzryWithJzJbxxDTO;
import com.hzlj.position.locate.common.model.ReportVideoJzry;
import com.hzlj.position.locate.dao.ReportVideoJzryDao;
import com.hzlj.position.locate.service.ReportVideoJzryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 通信联络核查-视频核验(ReportVideoJzry)表服务接口
 *
 * @author makejava
 * @date 2023-12-26 11:55:14
 */
@Slf4j
@Service
public class ReportVideoJzryServiceImpl implements ReportVideoJzryService {
    @Resource
    private ReportVideoJzryDao reportVideoJzryDao;

    @Override
    public void upsert(boolean call,List<ReportVideoJzryUpsertDTO> dtos) {
        if (ObjectUtil.isEmpty(dtos)) {
            return;
        }
        List<ReportVideoJzry> jzries = BeanUtil.copyToList(dtos,ReportVideoJzry.class);
        for (ReportVideoJzry jzry : jzries) {
            ReportVideoJzry exists = this.reportVideoJzryDao.getById(jzry.getId());
            //更新
            if (ObjectUtil.isNotEmpty(exists)) {
                jzry.setUpdateTime(new Date());
                this.reportVideoJzryDao.updateByJzId(call,jzry);
                continue;
            }
            jzry.setCreateTime(new Date());
            this.reportVideoJzryDao.save(jzry);
        }
    }


    /**
     * 查询列表：不分页
     */
    @Override
    @DictConvert
    public List<ReportVideoJzryWithJzJbxxDTO> listReportVideoJzry(ReportVideoJzryQueryParamDTO dto) {
        return this.reportVideoJzryDao.listReportVideoJzry(dto);
    }

    /**
     * 查询列表：分页
     */
    @Override
    @DictConvert
    public QueryPageResultDTO<ReportVideoJzryWithJzJbxxDTO> pageReportVideoJzry(ReportVideoJzryQueryParamDTO dto, PageParamDTO page) {
        return this.reportVideoJzryDao.pageReportVideoJzry(dto, page);
    }
}
